import React from 'react'
import {connect} from 'react-redux'
import getPeriods  from '../../actions/periodAction.js'
import {Link} from 'react-router'
import _ from 'underscore'
const Period = React.createClass({
	componentWillMount() {
	    const {fetchPeriod} =  this.props;
	    fetchPeriod();
	},
	render(){
		return(
			<div>
				<h3><Link to="/periods/new">新增合同期限</Link>合同期限管理</h3>
				<table>
					<thead>
					  <tr>
					    <th>序号</th>
					    <th>名称</th>
					    <th>月份数</th>
					    <th>描述</th>
					    <th></th>
					  </tr>
				  </thead>
				<tbody>
				{
					_.map(this.props.periods,function(value,index){
						return (
							<tr key={index}> 
								<td>{index+1}</td> 
								<td>{value.name}</td> 
								<td>{value.amount}</td> 
								<td></td>
							</tr>
						);
					})
				}
				</tbody>
				</table> 
			</div>
		)
	}
});
const mapStateToProps = (state) => {
  return {
    periods: state.period
  }
}


module.exports = connect(mapStateToProps, getPeriods)(Period);





